<?php
/**
 * Created by Pako
 * Date: 2018/8/19
 * Time: 16:33
 */

namespace App\Http\Controllers\Admin\Auth;


use App\Http\Controllers\Controller;
use App\Http\Request\Auth\RoleStore;
use App\Repositories\Auth\RoleRepository;
use Illuminate\Http\Request;

class RoleController extends Controller
{
    private $role;

    public function __construct(RoleRepository $role)
    {
        $this->role = $role;
    }

    public function index()
    {
        return $this->role->list();
    }


    /**
     *
     * 角色详情
     * @author Paco
     * @createTime 2018/8/23 12:13
     * @param $role_id
     * @return mixed
     */
    public function show($role_id)
    {
        return $this->role->show($role_id);
    }


    /**
     * 添加角色
     *
     * @author Pako
     * @createTime 2018/8/19 17:13
     * @param RoleStore $role
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(RoleStore $role, Request $request)
    {
        $data = $role->validated($request);
        return $this->role->store($data);
    }

    /**
     *
     * 更新角色
     * @author Paco
     * @createTime 2018/8/21 11:41
     * @param RoleStore $role
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function save(RoleStore $role, Request $request)
    {
        $data = $role->validated($request);
        return $this->role->save($data);
    }

    /**
     *
     * 更新状态
     * author Paco
     * createTime 2019/2/2 15:21
     * @param Request $request
     * @return mixed
     */
    public function saveStatus(Request $request)
    {
        $role_id = $request->input('role_id', 0);
        $status = $request->input('status', 0);
        return $this->role->saveStatus(['role_id' => $role_id, 'status' => $status]);
    }

    /**
     *
     * 删除角色
     * @author Paco
     * @createTime 2018/8/21 10:02
     * @param $role_id
     * @return mixed
     */
    public function del($role_id)
    {
        return $this->role->del($role_id);
    }
}